package cn.iocoder.yudao.module.reading.controller.app.ai;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.reading.controller.app.ai.vo.AiPolishReqVO;
import cn.iocoder.yudao.module.reading.controller.app.ai.vo.AiPolishRespVO;
import cn.iocoder.yudao.module.reading.service.ai.AiService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 用户 APP - AI 服务
 *
 * @author 芋道源码
 */
@Tag(name = "用户 APP - AI 服务")
@RestController
@RequestMapping("/reading/ai")
@Validated
@Slf4j
public class AiController {

    @Resource
    private AiService aiService;

    @PostMapping("/polish")
    @Operation(summary = "AI文本处理（润色/翻译）")
    public CommonResult<AiPolishRespVO> processText(@Valid @RequestBody AiPolishReqVO reqVO) {
        String processedContent;
        if ("translate".equals(reqVO.getOperation())) {
            processedContent = aiService.translateText(reqVO.getContent(), reqVO.getSourceLanguage(), reqVO.getTargetLanguage());
        } else {
            processedContent = aiService.polishText(reqVO.getContent());
        }
        return success(new AiPolishRespVO().setContent(processedContent));
    }

}
